package online.misscl.lsy.config;

import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.context.annotation.Configuration;
import org.springframework.web.servlet.config.annotation.ResourceHandlerRegistry;
import org.springframework.web.servlet.config.annotation.WebMvcConfigurer;

@Configuration
@Slf4j
public class FileConfig implements WebMvcConfigurer {

    @Value("${linux.upload-file-path}")
    String linuxUploadFilePath;
    @Value("${windows.upload-file-path}")
    String windowsUploadFilePath;

    @Override
    public void addResourceHandlers(ResourceHandlerRegistry registry){
        String os = System.getProperty("os.name");
        if (os != null && os.toLowerCase().startsWith("windows")) {

            registry.addResourceHandler("/img/**")
                    .addResourceLocations("file:" + windowsUploadFilePath);
        } else if (os != null && os.toLowerCase().startsWith("linux")) {

            registry.addResourceHandler("/img/**")
                    .addResourceLocations("file:" + linuxUploadFilePath);
        }
        log.info("当前系统版本是:{}",os);

    }
}
